
var animateUtil = (function () {

	var
		move;
	
	var
		updateMoveAnimation;
	
	var 
		stateMap = {};
	
	var requestAnimationFrame = 
			window.requestAnimationFrame ||
		    window.mozRequestAnimationFrame ||
		    window.webkitRequestAnimationFrame ||
		    window.msRequestAnimationFrame;
	
	/*****************Utility Methods Start***********************/
	
	updateMoveAnimation = function () {
		
		stateMap.that.offset({
			top: stateMap.top,
			left: stateMap.left
		});
		
		/*if (stateMap.hold) {
			requestAnimationFrame(updateMoveAnimation);
		}*/
		
	};
	
	/*****************Utility Methods End***********************/
	
	/*****************Public Methods Start***********************/
	
	/**
	 * 使 jQuery 对象中的元素可移动
	 * 
	 * 参数：
	 * 	obj -- jQuery 对象
	 * 
	 */
	move = function (obj) {
		
		obj.each(function () {
			
			$that = $(this);
			
			if ($that.data('animate-move-mark')) {
				//console.log('mark hit!');
				return;
			}
			
			$that.data('animate-move-mark', true);
			
			$that.children('.popTitle').on('mousedown', function (e) {
				
				stateMap = {
					that: $that,
					top: $that.offset().top,
					left: $that.offset().left,
					hold: true
				};
				
				var 
					diffX = e.clientX - stateMap.left,
					diffY = e.clientY - stateMap.top;
					
				$(window)
					.on('mousemove', function (e) {
						
						stateMap.left = e.clientX - diffX;
						stateMap.top = e.clientY - diffY;
						
						//requestAnimationFrame(updateMoveAnimation);
						
						updateMoveAnimation();
					
						return false;
					})
					.one('mouseup', function () {
						$(window).off('mousemove');
						stateMap.hold = false;
					});
	            
	            return false;
				
			}).css('cursor', 'move');
			
		});
	
	};
	
	/*****************Public Methods End*************************/
	
	//返回公共方法
	return {
		move: move
	};

})();